#ifndef BEATSLISTMODEL_H
#define BEATSLISTMODEL_H
#include "beats.h"
#include "ecg.h"

#include <QAbstractListModel>
class BeatsData {
public:
    BeatsData(int r, QString l, int rr = 0, int s = 0, int qoffset = 0, int soffset = 0, int test1 = 0, int test2 = 0, int test3 = 0, int test4 = 0, int test5 = 0, int test6 = 0, int test7 = 0, int test8 = 0, int test9 = 0, int test10 = 0)
        : rPeaksInAll(r)
        , label(l)
        , rrIntervals(rr)
        , selected(s)
        , qOffset(qoffset)
        , sOffset(soffset)
        , test1(test1)
        , test2(test2)
        , test3(test3)
        , test4(test4)
        , test5(test5)
        , test6(test6)
        , test7(test7)
        , test8(test8)
        , test9(test9)
        , test10(test10)
    {
    }
    int rPeaksInAll;
    QString label;
    int rrIntervals;
    int selected;
    int qOffset;
    int sOffset;
    int test1;
    int test2;
    int test3;
    int test4;
    int test5;
    int test6;
    int test7;
    int test8;
    int test9;
    int test10;
};
class BeatsListModel : public QAbstractListModel {
    Q_OBJECT

public:
    explicit BeatsListModel(QObject* parent = nullptr);
    enum MyRoles {
        rPeaksInAllRole = Qt::UserRole + 1,
        labelRole,
        rrIntervalsRole,
        selectedRole,
        qOffsetRole,
        sOffsetRole,
        test1Role,
        test2Role,
        test3Role,
        test4Role,
        test5Role,
        test6Role,
        test7Role,
        test8Role,
        test9Role,
        test10Role,
    };
    Q_ENUM(MyRoles);
    // Basic functionality:
    int rowCount(const QModelIndex& parent = QModelIndex()) const override;

    QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;

    virtual QHash<int, QByteArray> roleNames() const override;

    Q_INVOKABLE MyRoles getRPeaksInAllRole();
    Q_INVOKABLE MyRoles getLabelRole();
    Q_INVOKABLE void getFragmentBeats(int start, int duration);
    Q_INVOKABLE void refreshMData(QVector<int> rPeaksInAlls);
    Q_INVOKABLE void refreshListInBeatsModelData(); //用beatsModel中的数据刷新列表
    Q_INVOKABLE void refreshListInBeatsModelCircleSelectBeats(); //使用圈选的数据刷新列表

    int getBeatsCount() const;
    void setBeatsCount(int newBeatsCount);

signals:
    void beatsCountChanged();

private:
    Beats& beatsModel = Beats::getInstance();
    Ecg& ecg = Ecg::getInstance();
    QList<BeatsData> m_data;
    int beatsCount;
    Q_PROPERTY(int beatsCount READ getBeatsCount WRITE setBeatsCount NOTIFY beatsCountChanged FINAL)
};

#endif // BEATSLISTMODEL_H
